package bat.crimea.ua.maven.plugin.increment;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;

import java.util.List;

/**
 *
 *
 * @goal touch
 * @phase process-sources
 */
public class IncrementMojo extends AbstractMojo {


    /**
     * @parameter property="project" default-value="${project}" description="Current MAVEN project"
     * @required
     * @readonly
     */
    protected MavenProject _project;

    /**
     * @parameter type="java.util.List<bat.crimea.ua.maven.plugin.increment.ValueItem>" description="Value for processing"
     * @required
     */
    protected List<ValueItem> values;

    public void setProject(MavenProject project) {
        this._project = project;
    }

    @Override
    public void execute() throws MojoExecutionException {
        getLog().debug("Start: execute");
        for (ValueItem valueItem : values) {
            valueItem.init(this);
            getLog().debug(valueItem.toString());
            String result = valueItem.process();
            getLog().info("Maven Increment Plugin result '${" + valueItem.getOutputPropertyName() + "}' is: " + result);
            _project.getProperties().setProperty(valueItem.getOutputPropertyName(), result);
        }
    }
}
